﻿using System;
using System.Data;
using System.Collections.Generic;
using OgilvyOne.Model;
using OgilvyOne.DALFactory;
using OgilvyOne.IDAL;
namespace OgilvyOne.BLL
{
    /// <summary>
    /// ActivityMessagesManageBll
    /// </summary>
    public partial class ActivityMessagesManageBll
    {
        private readonly IActivityMessagesManage dal = ActivityMessagesManageFactory.create();
        public ActivityMessagesManageBll()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int messageId)
        {
            return dal.Exists(messageId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ActivityMessagesManageModel model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ActivityMessagesManageModel model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int messageId)
        {

            return dal.Delete(messageId);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string messageIdlist)
        {
            return dal.DeleteList(messageIdlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ActivityMessagesManageModel GetModel(int messageId)
        {

            return dal.GetModel(messageId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ActivityMessagesManageModel> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ActivityMessagesManageModel> DataTableToList(DataTable dt)
        {
            List<ActivityMessagesManageModel> modelList = new List<ActivityMessagesManageModel>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ActivityMessagesManageModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new ActivityMessagesManageModel();
                    if (dt.Rows[n]["MESSAGE_ID"].ToString() != "")
                    {
                        model.Messageid = int.Parse(dt.Rows[n]["MESSAGE_ID"].ToString());
                    }
                    if (dt.Rows[n]["ACTIVITY_ID"].ToString() != "")
                    {
                        model.Activityid = int.Parse(dt.Rows[n]["ACTIVITY_ID"].ToString());
                    }
                    model.Messagecontent = dt.Rows[n]["MESSAGE_CONTENT"].ToString();
                    if (dt.Rows[n]["MEMBER_ID"].ToString() != "")
                    {
                        model.Memberid = int.Parse(dt.Rows[n]["MEMBER_ID"].ToString());
                    }
                    if (dt.Rows[n]["IS_VIEW"].ToString() != "")
                    {
                        model.Isview = int.Parse(dt.Rows[n]["IS_VIEW"].ToString());
                    }
                    if (dt.Rows[n]["MESSAGE_TIME"].ToString() != "")
                    {
                        model.Messagetime = DateTime.Parse(dt.Rows[n]["MESSAGE_TIME"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

